From: Ximin Luo Date: Mon, 5 Feb 2018 15:15:13 +0000 (+0100) Subject: Only avoid dev deps in `cargo install` and `cargo build --avoid-dev-deps` X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~56^2~7 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=ee78456afbf56b27128955c90329552977ef0b24;p=cargo.git Only avoid dev deps in `cargo install` and `cargo build --avoid-dev-deps` --- diff --git a/src/bin/build.rs b/src/bin/build.rs index 889052068..9b576e922 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -12,6 +12,7 @@ pub struct Options { flag_features: Vec, flag_all_features: bool, flag_no_default_features: bool, + flag_avoid_dev_deps: bool, flag_target: Option, flag_manifest_path: Option, flag_verbose: u32, @@ -63,6 +64,7 @@ Options: --features FEATURES Space-separated list of features to also build --all-features Build all available features --no-default-features Do not build the `default` feature + --avoid-dev-deps Avoid installing dev-dependencies if possible --target TRIPLE Build for the target triple --manifest-path PATH Path to the manifest to compile -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) @@ -98,7 +100,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { &options.flag_z)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; - let ws = Workspace::new(&root, config)?; + let mut ws = Workspace::new(&root, config)?; + if options.flag_avoid_dev_deps { + ws.set_require_optional_deps(false); + } let spec = Packages::from_flags(options.flag_all, &options.flag_exclude, diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 5d21dd8d4..00e93a927 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -300,6 +300,11 @@ impl<'cfg> Workspace<'cfg> { self.require_optional_deps } + pub fn set_require_optional_deps<'a>(&'a mut self, require_optional_deps: bool) -> &mut Workspace<'cfg> { + self.require_optional_deps = require_optional_deps; + self + } + /// Finds the root of a workspace for the crate whose manifest is located /// at `manifest_path`. /// diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index a212a6455..bf905c3af 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -228,7 +228,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, let specs = spec.into_package_id_specs(ws)?; let features = Method::split_features(features); let method = Method::Required { - dev_deps: filter.need_dev_deps(), + dev_deps: ws.require_optional_deps() || filter.need_dev_deps(), features: &features, all_features, uses_default_features: !no_default_features, diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index c85923e45..703a96da4 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -175,7 +175,11 @@ fn install_one(root: &Filesystem, let ws = match overidden_target_dir { Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?, - None => Workspace::new(pkg.manifest_path(), config)?, + None => { + let mut ws = Workspace::new(pkg.manifest_path(), config)?; + ws.set_require_optional_deps(false); + ws + } }; let pkg = ws.current()?;